import gwc.domain.User

if (params.user) {
	if (User.get(params.user)) {
		request.userExists = true
	} else {
		def user = new User(name : params.user, password : params.password)
		user.save()

		assert User.get(user.name)

		request.getRequestDispatcher('connect.groovy').forward(request, response)
		return

	}
}

html.html {
	head {}

	body {
		form (action : 'register.groovy', method : 'post') {
			if (request.userExists) {
				div ('user already existed')
			}
			div {
				label ('User : ')
				input (type : 'text', name : 'user', value : (params.user ?: "" ))
			}
			div {
				label ('Password : ')
				input (type : 'password', name : 'password', value : (params.password ?: ""))
			}
			div {
				input (type : 'submit', value : 'Register')
			}
		}
	}
}